<?php
class ChucvusvsController extends AppController {

	var $name = 'Chucvusvs';

	function index() {
		$this->Chucvusv->recursive = 0;
		$this->set('chucvusvs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid chucvusv', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('chucvusv', $this->Chucvusv->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Chucvusv->create();
			if ($this->Chucvusv->save($this->data)) {
				$this->Session->setFlash(__('The chucvusv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The chucvusv could not be saved. Please, try again.', true));
			}
		}
		$chucvs = $this->Chucvusv->Chucv->find('list');
		$sinhviens = $this->Chucvusv->Sinhvien->find('list');
		$this->set(compact('chucvs', 'sinhviens'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid chucvusv', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Chucvusv->save($this->data)) {
				$this->Session->setFlash(__('The chucvusv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The chucvusv could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Chucvusv->read(null, $id);
		}
		$chucvs = $this->Chucvusv->Chucv->find('list');
		$sinhviens = $this->Chucvusv->Sinhvien->find('list');
		$this->set(compact('chucvs', 'sinhviens'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for chucvusv', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Chucvusv->delete($id)) {
			$this->Session->setFlash(__('Thông tin đã xóa', true),'success');
			$this->redirect(array('controller'=>'z1chucvusvs','action'=>'index'));
		}
		$this->Session->setFlash(__('Thông tin không thể xóa', true),'error');
		$this->redirect(array('controller'=>'z1chucvusvs','action' => 'index'));
	}
}
